A shell script is a computer program designed to be run by the Unix/Linux shell which could be one of the following:
- The Bourne Shell
- The C Shell
- The Korn Shell
- The GNU Bourne-Again Shell
A shell is a command-line interpreter and typical operations performed by shell scripts include file manipulation, program execution, and printing text.
Sample Shell Scripts
#!/bin/sh
echo "What is your name?"
read PERSON
echo "Hello, $PERSON"
How to Run Shell Script
Sample Shell Scripts
#!/bin/sh
echo "What is your name?"
read PERSON
echo "Hello, $PERSON"
How to Run Shell Script
sh <Script Name>
Defining variable
Name="Suma"
age=34
Accessing Values
To access the value stored in a variable, prefix its name with the dollar sign ($)
Name="Suma"
age=34
echo $Name
echo $age
Variable Type
#!/bin/sh
echo "Enter first number"
read a
echo "Enter second number"
read b
if [ $a == $b ]
then
echo "a is equal to b"
fi
if [ $a != $b ]
then
echo "a is not equal to b"
fi
Defining variable
Name="Suma"
age=34
Accessing Values
To access the value stored in a variable, prefix its name with the dollar sign ($)
Name="Suma"
age=34
echo $Name
echo $age
Variable Type
- Local Variable
- Environment Variable
- Shell Variable
#!/bin/sh
echo "Enter first number"
read a
echo "Enter second number"
read b
if [ $a == $b ]
then
echo "a is equal to b"
fi
if [ $a != $b ]
then
echo "a is not equal to b"
fi
No comments:
Post a Comment